<?php
namespace Home\Org\Util;
class SapBrand
{
    static private $_instance = null;
    private $model;
    private $brandListDetail;
    private $brandListOptions;
    private $brandListPureArray;

    static public function getInstance()
    {
        if (is_null(self::$_instance)) {
            self::$_instance = new SapBrand();
        }
        return self::$_instance;
    }

    public function getModel()
    {
        return $this->model;
    }

    private function __construct()
    {
        $this->model = M('sapBrand');
        $resultArray = $this->model->field("b_name,b_id")->where("examine_status=1")->order('b_name desc')->select();
        $this->brandListDetail = $resultArray;
        foreach ($resultArray as $key => $item){
            $this->brandListOptions[] = array('id'=>$item['b_id'],'text'=>$item['b_name']);
            $this->brandListPureArray[$item['b_id']] = $item['b_name'];
        }
    }

    /**
     * @return mixed
     */
    public function getBrandListOptions()
    {
        return $this->brandListOptions;
    }

    public function getPPNameByPPList($ppList)
    {
        $ppArrayById = explode(',',$ppList);
        $tmpList = "";

        foreach ($ppArrayById as $key => $item)
        {
            $tmpList .= $this->brandListPureArray[$item].',';
        }

        $ppNameList = substr($tmpList,0,strlen($tmpList)-1);
        $ppNameList = str_replace('\'','\'\'',$ppNameList);
        $ppNameList=mb_convert_encoding($ppNameList,'gbk','utf-8');

        return $ppNameList;
    }

}